import { addPost } from "@/api/post";
import { Button, Form, Input, message } from "antd";
import { Component } from "react";
import ReactQuill from "react-quill";
import "react-quill/dist/quill.snow.css";

import Markdown from "@/components/markdown";

export default class PostsAdd extends Component {
  render() {
    return (
      <div>
        <h1>新增帖子</h1>

        <Form onFinish={this.onFinish}>
          <Form.Item name="title" label="标题">
            <Input />
          </Form.Item>

          {/* <Form.Item name="body" label="正文" style={{ height: 300 }}>
            <ReactQuill style={{ height: 200 }} />
          </Form.Item> */}

          <Form.Item name="body" label="正文">
            <Markdown />
          </Form.Item>

          <Form.Item>
            <Button type="primary" htmlType="submit">
              新增
            </Button>
          </Form.Item>
        </Form>
      </div>
    );
  }

  onFinish = (values: any) => {
    console.log("values", values);
    addPost(values).then(() => {
      message.success("新增成功");
    });
  };
}
